var vm = avalon.define({
	$id: "forgetPassword",
	tel:"",//手机号
	password:"",//密码
	codenub:"",//验证码
	path1:"",//图片验证码显示的图片地址
	txtusersend:"发送验证码",//发送验证码文字
	imgcode1:"",//图形验证码
	captcha_key:"",//获取图片对应的key值
	imgcode1show:false,//对应的获取图片是否显示，false不显示
	text1show:true,//点击获取图片显示
	repassword:"",//再次输入密码
	SMSSendClick:false,//发送按钮是否可以点击，false可以点击
	imgchange: function() {
			vm.text1show = false;
			vm.imgcode1show = true;
			//获取验证码接口请求
			getData(api_captcha, {}, function(res) {
			    console.log(res);
			    if (res.status == 'SUCCESS') {
						vm.path1 = res.data[0].captcha_image_content; //改变对应的src值
						vm.captcha_key = res.data[0].captcha_key; //赋值获取图片对应的key值
						console.log(vm.captcha_key);
			    } else {
						alert(res.msg);
					}
				});
			
			vm.timeClickSign = !vm.timeClickSign; //是否可以点击事件取反
			setTimeout(function() {
				vm.timeClickSign = !vm.timeClickSign;
			}, 3000);
	},
	// 发送短信验证码
	SMSSend: function(btnid) {
			var second = 60; //初始化60s
			if (vm.SMSSendClick === true) {
				return false;
			}
			if(vm.tel == ""){
				alert('手机号不能为空');
				return false;
			}else if (vm.imgcode1 == "") {
				alert("图形验证码不能为空");
				return false;
			}
			//逻辑方法
			//发送短信验证码接口请求
			getData(api_sendsms, {
				mobile: vm.tel,
				verification_code: vm.imgcode1,
				verification_key: vm.captcha_key
			}, function(res) {
				console.log(res);
				if (res.status == 'SUCCESS') {
					//倒计时60s
					vm.SMSSendClick = true; //发送短信按钮禁止点击
					var time = setInterval(function() {
						if (second > 0) {
							vm.txtusersend = "剩余" + second + "秒"; //对应的发送验证码按钮改成剩余60s
							second--;
							console.log(vm.txtusersend);
						} else {
							vm.SMSSendClick = false; //倒计时结束按钮能点击
							vm.txtusersend = "发送验证码"; //对应的发送验证码按钮改成发送验证码
							clearInterval(time) //清除定时器
						}
					}, 1000)
					alert(res.msg);
				} else {
	
					alert(res.msg);
				}
	
			});
	},
	sureClick: function() {
		if(vm.tel == ""){
			alert('手机号不能为空');
			return false;
		}else if (!mobilephoneReg.test(vm.tel)){
			alert('手机号格式不正确');
			return false;
		}else if(vm.codenub == ""){
			alert('验证码不能为空');
			return false;
		}else if(vm.password == ""){
			alert('密码不能为空');
			return false;
		}else if(vm.repassword == ""){
			alert('确认密码不能为空');
			return false;
		}else if(vm.repassword != vm.password){
			alert('确认密码和密码不一致');
			return false;
		}
		console.log(1);
		//忘记密码请求
		postData(api_updatepwd,{
			token: '',
			mobile:vm.tel,
			mobile_check_code:vm.codenub,
			password:vm.password,
			password_confirmation:vm.repassword
		}, function(res) {
			console.log(res);
			if (res.status == 'SUCCESS') {
				alert(res.msg);
				window.location.href = './login.html'
			} else {
				alert(res.msg);
			}
		});
		return true;
	}
	
})